package com.priv.controller;

import com.priv.domain.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

/**
 * @author : 十一
 * @data : 15:12 2022/12/27
 * When in doubt, use brute force.
 */
@Controller
public class UserController {

    /**
     * 响应页面 跳转页面
     */
    @RequestMapping("/toJumpPage")
    public String toJumpPage(){
        System.out.println("跳转页面");
        return "index.jsp";
    }

    /**
     * 响应文本数据
     */
    @RequestMapping("/toText")
    @ResponseBody
    public String toText(){
        System.out.println("返回纯文本数据");
        return "response text";
    }

    /**
     * 响应POJO对象
     */
    @RequestMapping("/toJsonPOJO")
    @ResponseBody
    public User toJsonPOJO(){
        System.out.println("返回json对象数据");
        User user = new User();
        user.setName("Jack");
        user.setAge(19);
        return user;
    }

    /**
     * 响应POJO集合对象
     */
    @RequestMapping("/toJsonList")
    @ResponseBody
    public List<User> toJsonList(){
        System.out.println("返回json集合数据");
        User user1 = new User();
        user1.setName("Java");
        user1.setAge(14);

        User user2 = new User();
        user2.setName("Go");
        user2.setAge(10);

        ArrayList<User> userList = new ArrayList<>();
        userList.add(user1);
        userList.add(user2);

        return userList;
    }
}
